﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using InfFront.InfoViews.Base;

namespace InfFront.InfoViews.WPF
{
    /// <summary>
    /// Interaction logic for EntryEditWindow.xaml
    /// </summary>
    public partial class EntryEditWindow : Window
    {
        #region Private Variables
        private InfoViewEntry source;
        #endregion Private Variables

        #region Construction/Initialization
        public EntryEditWindow()
        {
            InitializeComponent();

            editFrame.IsInCloseableWindow = true;
            editFrame.CloseButtonClick += editFrame_CloseButtonClick;
        }

        public EntryEditWindow(InfoViewEntry source)
        {
            this.source = source;
            this.DataContext = source;
            InitializeComponent();

            editFrame.IsInCloseableWindow = true;
            editFrame.CloseButtonClick += editFrame_CloseButtonClick;
            editFrame.DataContext = source;
        }

        public void SetSource(InfoViewEntry source)
        {
            if (this.source == source)
                return;

            this.source = source;
            this.DataContext = source;

            editFrame.DataContext = source;
        }

        #endregion Construction/Initialization

        void editFrame_CloseButtonClick(object sender, EventArgs e)
        {
            Close();
        }

        private void this_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            editFrame.CloseButtonClick -= editFrame_CloseButtonClick;
        }
    }
}
